home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1998 March / Macworld (1998-03) (Disk 1).dmg / Shareware World / Utilities / Text Processing / Alpha / Tcl / Modes / scilabMode.tcl < prev    next >
Encoding:
Text File  |  1997-12-08  |  5.8 KB  |  194 lines  |  [TEXT/ALFA]

  1. ## -*-Tcl-*- (install)
  2.  # ###################################################################
  3.  #  Vince's Additions - an extension package for Alpha
  4.  # 
  5.  #  FILE: "scilabMode.tcl"
  6.  #                                    created: 15/4/97 {4:03:22 pm} 
  7.  #                                last update: 8/12/97 {10:24:09 am} 
  8.  #  Author: Vince Darley
  9.  #  E-mail: <darley@fas.harvard.edu>
  10.  #    mail: Division of Applied Sciences, Harvard University
  11.  #          Oxford Street, Cambridge MA 02138, USA
  12.  #     www: <http://www.fas.harvard.edu/~darley/>
  13.  #  
  14.  #  Mode for 'Scilab'
  15.  #  
  16.  # Installation:
  17.  # 
  18.  #  Requires Alpha version 7.0 or newer.  Just drop this file into
  19.  #  the Alpha:Tcl:Modes: folder, rebuild your Tcl indices (using
  20.  #  the Tcl menu which will be there when you read this file in Alpha)
  21.  #  then quit and restart Alpha.  Now any file ending in '.sci' 
  22.  #  automatically opens in Scilab mode.  You also need to paste the
  23.  #  included icon from 'newMenuIcons.rsrc' into Alpha.  If for some
  24.  #  reason you got this file without that rsrc file, then add the line
  25.  #  'set scilabMenu "Scil"' to your prefs.tcl file.  Note: the more
  26.  #  useful features of this mode are only available if you've
  27.  #  installed "Vince's Additions".
  28.  #  
  29.  #  We can't do too much exciting, since Scilab only handles an
  30.  #  'open' apple-event --- therefore it's not usefully scriptable.
  31.  #  
  32.  # Features:
  33.  # 
  34.  #  Automatically scans Scilab's 'Help' directory to pick up all
  35.  #  Scilab keywords so they can be coloured.
  36.  #  
  37.  #  Command-clicking on a keyword opens up a window with the help
  38.  #  information for that keyword (optionally this can be made to
  39.  #  open in Scilab itself)
  40.  #  
  41.  # If Vince's Additions is installed, the following features are
  42.  # also available:
  43.  # 
  44.  #  Keywords can be completed (enter the first few letters 
  45.  #  followed by 'cmd-tab')
  46.  #  
  47.  #  Function calls can be extended to list their arguments,
  48.  #  with template stops at each argument (again use cmd-tab).
  49.  #  
  50.  #  e.g. type 'sysl<cmd-tab>' and it is completed to 'syslin'
  51.  #  and immediately expanded to:
  52.  #      syslin(•<dom>,•<A>,•<B>,•<C >•<[,D [,x0] ]>)•
  53.  #  pressing tab moves from one argument to the next, highlighting
  54.  #  each argument in turn for each entry.
  55.  #  
  56.  # This file is copyright Vince Darley 1997, but freely distributable
  57.  # provided you note any modifications you make below.
  58.  # ###################################################################
  59.  ##
  60.  
  61. alpha::mode Scil 1.0 scilabMenu {*.sci *.dem} scilabMenu {
  62.     addMenu scilabMenu "•283"
  63. }
  64.  
  65. newPref f alphaOpensHelpFiles 1 Scil
  66. newPref f wordBreak {[\w_]+} Scil
  67. newPref f wordBreakPreface {[^_\w]} Scil
  68. newPref v stringColor green Scil
  69. newPref v commentColor red Scil
  70. newPref v keywordColor blue Scil
  71.  
  72. proc scilabMenu {} {}
  73.  
  74. menu -n $scilabMenu -p Scil::menuProc {
  75.     "/S<U<OswitchToScilab"
  76.     "(-"
  77.     "/K<U<OopenFileInScilab"
  78.     "/K<U<O<BswitchFileToScilab"
  79.     "/C<O<UsetClipboardToExecFile"
  80.     "rebuildScilabKeywords"
  81. }
  82.  
  83.  
  84. proc Scil::menuProc {menu item} {
  85.     switch $item {
  86.         switchToScilab {app::launchFore SLab}
  87.         openFileInScilab {
  88.             openAndSendFile SLab
  89.         }
  90.         switchFileToScilab {
  91.             openAndSendFile SLab
  92.             killWindow
  93.         }
  94.         setClipboardToExecFile {
  95.             putScrap "exec('[win::CurrentTail]')"
  96.         }
  97.         rebuildScilabKeywords {Scil::RebuildElectrics}
  98.     }
  99. }
  100.  
  101. set completions(Scil) \
  102.     {completion::cmd completion::electric completion::word}
  103.  
  104. proc Scil::RebuildElectrics {} {
  105.     # Get keywords by looking for all help documents,
  106.     # simple but effective.  There may be a better way.
  107.     global Scilcmds PREFS Scilelectrics
  108.     set p [pwd]
  109.     set dir  "[file dirname [nameFromAppl SLab]]:man:"
  110.     cd $dir
  111.     regsub -all ".hlp" [glob *.hlp] "" Scilcmds
  112.     cd $p
  113.     set Scilcmds " ${Scilcmds} "
  114.     set fout [open ${PREFS}:ScilData w]
  115.     puts $fout "set Scilcmds \{${Scilcmds}\}"
  116.     foreach f $Scilcmds {
  117.         message "scanning $f…"
  118.         set fileid [open "${dir}${f}.hlp" "r"]
  119.         set contents [read $fileid]
  120.         close $fileid
  121.         if [regexp "NAME\[ \r\n\t\]+${f} - (\[^\r\n\]*)\[ \r\n\t\]+CALLING SEQUENCE\[ \r\n\t\]+(${f}|\[^=\]+= *${f})(\(\[^\r\n\]+)\)\[ \r\n\t]" \
  122.             $contents dummy desc dmy arg] {
  123.             if [regexp  {\((.*)\)(.*)} $arg dmy in after] {
  124.                 if [regexp {(, *)?\[.*\]} $in brace] {
  125.                     regsub {(, *)?\[.*\]} $in {◊} in
  126.                     regsub -all {,} $in {•,•} in
  127.                     if {$in != "◊"} {
  128.                         regsub {◊} $in "••${brace}•" in
  129.                         set in "(•${in})$after"
  130.                     } else {
  131.                         regsub {◊} $in "•${brace}•" in
  132.                         set in "(${in})$after"
  133.                     }
  134.                 } else {
  135.                     regsub -all {,} $in {•,•} in
  136.                     if {$in != ""} {
  137.                         set in "(•${in}•)$after"
  138.                     } else {
  139.                         set in "()$after"
  140.                     }
  141.                 }
  142.                 set Scilelectrics($f) "${in}•$desc•"                
  143.             } else {
  144.                 set Scilelectrics($f) "${arg}•$desc•"
  145.             }
  146.             puts $fout "set Scilelectrics($f) \{$Scilelectrics($f)\}"
  147.         }
  148.     }
  149.     close $fout
  150.     message "done"
  151.     
  152. }
  153.  
  154. ## 
  155.  # -------------------------------------------------------------------------
  156.  # 
  157.  # "Scil::DblClick" --
  158.  # 
  159.  #  Open a help file for the given command, either in Alpha or externally
  160.  #  in Scilab.
  161.  # -------------------------------------------------------------------------
  162.  ##
  163. proc Scil::DblClick {from to shift option control} {
  164.     select $from $to
  165.     set text [getSelect]
  166.     set d "[file dirname [nameFromAppl SLab]]:man:"
  167.     set f "${d}${text}.hlp"
  168.     if [file exists $f] {
  169.         global alphaOpensHelpFiles
  170.         if $alphaOpensHelpFiles {
  171.             openFileQuietly $f
  172.             changeMode Scil
  173.             global win::Modes
  174.             set "win::Modes($f)" "Scil"
  175.             setWinInfo read-only 1
  176.         } else {
  177.             set name [file tail [app::launchFore SLab]]
  178.             sendOpenEvent noReply $name $f
  179.         }        
  180.     } else {
  181.         alertnote "No such help file exists in Scilab's 'man' directory."
  182.     }
  183. }
  184.  
  185. if [file exists ${PREFS}:ScilData] {
  186.     source "${PREFS}:ScilData"
  187. } else {
  188.     alertnote "The first time you use this mode I must build a command database."
  189.     Scil::RebuildElectrics
  190. }
  191. regModeKeywords  -e {//} -c $ScilmodeVars(commentColor) \
  192.     -k $ScilmodeVars(keywordColor)  -s $ScilmodeVars(stringColor) \
  193.     Scil $Scilcmds
  194.